﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StaffGrid.aspx.cs" Inherits="Base_School_StaffGrid" EnableEventValidation = "false" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>教师管理</title>
        
    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #load{width:500px;height:25px;border:1px #000 solid;}
        #loading{position:absolute;z-index:2;height:23;filter:progid:DXImageTransform.microsoft.gradient(gradienttype=1,startColorStr=white,endColorStr=#39867b);}
        #loadtext{position:absolute;z-index:3;width:100%;height:100%;line-height:23px;text-align:center;}
    </style>

    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />    
    <script type="text/javascript" src="../Common/Js/jquery.js"></script>
    <script type="text/javascript" src="../Common/Js/common.js"></script>
    <script type="text/javascript" src="../Common/Js/msg.js"></script>
    
</head>
<body>
    <div class="mainWarp">
        <div class="pageBody">
            <form id="form1" runat="server">
                <div>
                    <table style="margin-top: 10px;">
                        <tr>
                            <td style="padding-left: 5px;">
                                <input type="button" id="btnDel" value="移除" class="commonBut" onclick="DelTeacherClick();" />
                            </td>
                            <td style="padding-left: 5px;">
                                <input style="display: none;" type="button" id="btnUpToLeader" value="提升为教研组长" class="commonBut"
                                    onclick="UpToLeader();" />
                            </td>
                            <td style="padding-left: 5px;">
                                <input style="display: none;" type="button" id="btnDown" value="撤销教研组长" class="commonBut"
                                    onclick="DownLeader();" />
                            </td>
                            <td style="padding-left: 5px;">
                                <input style="display: none;" type="button" id="btnUpToGSLeader" value="备课组长设置" class="commonBut"
                                    onclick="ShowUpdateWindow();" />
                            </td>
                        </tr>
                    </table>
                </div>
                <div>
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>
                </div>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Repeater ID="Repeater1" runat="server">
                            <HeaderTemplate>
                                <table id="teacherTable" border="0" cellpadding="0" cellspacing="1" class="useList">
                                    <tr class="tableTitle">
                                        <!--<th width="5%" height="26">
                                            <input type="checkbox" onclick="CheckedAll(this);" /></th>-->
                                        <th width="15%" style="text-align: left; padding-left: 5px;">
                                            工号</th>
                                        <th width="20%" style="text-align: left; padding-left: 5px;">
                                            姓名</th>
                                        <th width="50%" style="text-align: left; padding-left: 5px;">
                                            职务</th>
                                    </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr id="<%# DataBinder.Eval(Container.DataItem, "RID") %>" onclick="SetHightLight(this);"
                                    style="background-color: White;">
                                    <!--<td height="26">
                                        <input type="checkbox" userid="<%# DataBinder.Eval(Container.DataItem, "RID") %>" /></td>-->
                                    <td name="TechCode" style="text-align: left; font-weight: normal; padding-left: 5px;"
                                        onselect="document.selection.empty()">
                                        <%# DataBinder.Eval(Container.DataItem, "TeachCode")%>
                                    </td>
                                    <td name="TechName" style="text-align: left; font-weight: normal; padding-left: 5px;"
                                        onselect="document.selection.empty()">
                                        <%# DataBinder.Eval(Container.DataItem, "TeachName")%>
                                    </td>
                                    <td style="text-align: left; font-weight: normal; padding-left: 5px;">
                                        <%# DataBinder.Eval(Container.DataItem, "DisplayString")%>
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>
                        <webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Right" pagesize="15"
                            width="100%" pagingbuttonspacing="10px" buttonimagealign="left" onpagechanged="AspNetPager1_PageChanged"> </webdiyer:aspnetpager>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
                <div style="display: none;">
                    <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                </div>
            </form>
            
            <div id="popTable" class="layoutWarp" style="display:none; width: 600px; overflow: inherit; text-align:left;">
                <div class="title">
                    <span id="formTitle">备课组长设置</span> <a title="关闭" onclick="return CloseMask('popTable')">
                        关闭</a>
                </div>
                <table style="width: 596px; margin-bottom: 12px;">
                    <tr>
                        <td style="padding-left:10px; padding-top:10px;">请选择此备课组长所管辖的年级:</td>
                    <tr>
                    <tr>
                        <td valign="top">
                            <div id="divTreeBox" style="height: 250px; overflow: auto; width: 596px;">
                                <table id="tableClassList" cellpadding="0" cellspacing="1" bordercolor="#c3dce5" style="width:556px; margin-left: 18px; border:0px;" >
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                                <input type="button" id="btnSave" value="保存" onclick="Save();" class="commonBut" />
                                <input type="button" value="取消" onclick=" CloseMask('popTable');" class="commonBut" />
                        </td>
                    </tr>
                </table>
            </div>
            
        </div>
    </div>
    
    <script type="text/javascript">
    var iCauseID = 0;
    var tree;
    var iEditTeachID = 0;
    
    window.onload = function() {
        var type = self.parent.currType;
        var obj1 = document.getElementById("btnUpToLeader");
        var obj2 = document.getElementById("btnUpToGSLeader");
        var obj3 = document.getElementById("btnDown");
        switch(type) {
            case "Subject":
                obj1.style.display = "block";
                obj1.value = "提升为教研组长";
                obj2.style.display = "block";
                obj3.style.display = "block";
                obj3.value = "撤销教研组长";
                break;  
            case "Grade":
                obj1.style.display = "block";
                obj1.value = "提升为年级组长";
                obj2.style.display = "none";
                obj3.style.display = "block";
                obj3.value = "撤销年级组长";
                break;
            case "Staff":
                obj1.style.display = "none";
                obj2.style.display = "none";
                obj3.style.display = "none";
                break;
        }
        Bind();
    }
    
    function jsright(rights,rightn) { 
        var sr=rights; 
        sr = sr.substring(sr.length-rightn,sr.length); 
        return sr; 
    }

//    //弹出对话框中的CheckBox操作结束
//    function CheckedAll(obj) {
//        var checkItems=document.getElementById("teacherTable").getElementsByTagName('input');
//        for(var i=0;i < checkItems.length;i++){
//　　　　    var checkItem= checkItems[i];
//　　　　    if(checkItem.type==='checkbox'){
//　　　　　    checkItem.checked = obj.checked ;
//　　　　    }
//　　    }
//    }
    
//    function ValidateChecked() {
//        var arr = new Array();
//        if(document.getElementById("teacherTable") != null)
//        {
//            var checkItems=document.getElementById("teacherTable").getElementsByTagName('input');
//　　        for(var i=1;i < checkItems.length;i++){
//　　　　        var checkItem= checkItems[i];
//　　　　        if(checkItem.type==='checkbox' && checkItem.checked)
//　　　　        {
//　　　　            arr.push(checkItem.userid);
//　　　　        }
//　　        }
//　　    }
//        return arr;
//    }
    
    function DelTeacherClick()
    {
        var type = self.parent.currType;
        switch(type)
        {
            case "Subject":
                showConfirmBox("删除", "此操作将会同时删除教师在此教研组下的任课信息, 确定删除?", DeleteList);
                break;
            case "Grade":
                showConfirmBox("删除", "此操作将会同时删除教师在此年级组下的任课信息, 确定删除?", DeleteList);
                break;
            case "Staff":
                DeleteList();
                break;
        }
    }
    
    // 批量删除教师信息
    function DeleteList() {
        var type = self.parent.currType;
        var teacherID = iEditTeachID;
        var groupID = self.parent.currCauseID;
        
        if(teacherID < 1)
            return;
        switch(type)
        {
            case "Subject":
                PageMethods.RemoveSubject(iEditTeachID, groupID, 
                    function(succ) {
                        Bind();
                    },
                    function(err) {
                        showMassgeBox("提示",USER_DEL_FAIL,1,null);
                    }
                );
                break;
            case "Grade":
                PageMethods.RemoveGrade(iEditTeachID, groupID, 
                    function(succ) {
                        Bind();
                    },
                    function(err) {
                        showMassgeBox("提示",USER_DEL_FAIL,1,null);
                    }
                );
                break;
            case "Staff":
                PageMethods.RemoveStaff(iEditTeachID, groupID, 
                    function(succ) {
                        Bind();
                    },
                    function(err) {
                        showMassgeBox("提示",USER_DEL_FAIL,1,null);
                    }
                );
                break;
        }

    }
    
    // 提升为年级组/教研组长
    function UpToLeader() {
        var gradeID = 0;
        var causeID = 0;
        var type = self.parent.currType;
        var teacherID = iEditTeachID;
        var groupID = self.parent.currCauseID;
        
        if(teacherID < 1) {
            showMassgeBox("提示","请选中一个教师.",1,null);
            return;
        }
        switch(type) {
            case "Subject":
                causeID = groupID;
                break;
            case "Grade":
                gradeID = groupID;
                break;
        }
        
        PageMethods.ToLeader(teacherID, causeID, gradeID, type, 
            function(succ){
                if (succ > 0) {
                    Bind();
                }
            },
            function(err) {
                showMassgeBox("提示",USER_DEL_FAIL,1,null);
            }
        );
    }
    
    // 撤职
    function DownLeader() {
        var gradeID = 0;
        var causeID = 0;
        var type = self.parent.currType;
        var teacherID = iEditTeachID;
        var groupID = self.parent.currCauseID;
        
        if(teacherID < 1) {
            showMassgeBox("提示","请选中一个教师.",1,null);
            return;
        }
        
        switch(type) {
            case "Subject":
                causeID = groupID;
                break;
            case "Grade":
                gradeID = groupID;
                break;
        }
        
        PageMethods.DownLeader(teacherID, causeID, gradeID, type, 
            function(succ){
                if (succ > 0) {
                    Bind();
                }
            },
            function(err) {
                showMassgeBox("提示",USER_DEL_FAIL,1,null);
            }
        );
    }
    
    // 添加窗口
    function ShowUpdateWindow() {
        var teacherID = iEditTeachID;
        if(teacherID < 1) {
            showMassgeBox("提示","请选中一个教师.",1,null);
            return;
        }
    
        ShowPopForm("popTable", "formTitle", "备课组长设置");
        //显示背景遮罩
        ShowMask();
        
        PageMethods.GetTeacherGradeInfo(iEditTeachID, self.parent.currCauseID, 
            function(succ){
                var table = document.getElementById('tableClassList');
                //table.rows
                while(table.rows.length > 0) {
                    table.deleteRow(table.rows[0]);  
                }
                
                if(succ == null || succ.length < 1) {
                    var c = table.insertRow().insertCell();
                    c.colSpan = 3;
                    c.innerText = "当前选中教师没有加入任何年级组内";
                     
                    return;
                }
                
                var newTr = null;
                
                for(var i = 0; i < succ.length; i++) {
                    if(i % 3 == 0) {
                        newTr = table.insertRow();
                    }
                    var newTd = newTr.insertCell();
                    newTd.innerHTML = "<input style='margin-left:5px;' id='grade_" +succ[i].Grade+ "' type='checkbox' name='cbGrade' value='" + succ[i].Grade +"'/>" + analyzeGrade(succ[i].Grade);
                }

                // 设置属性
                PageMethods.GetTeacherGSInfo(iEditTeachID, self.parent.currCauseID, 
                    function(succe) {
                        if(succe == null || succe.length < 1)
                            return;
                            //alert(succe.length);
                        var gradeArr = document.getElementsByName("cbGrade");
                        for(var j = 0; j < succe.length; j++) {
                            for(var x = 0; x < gradeArr.length; x++ ) {
                                //alert(succe[j].GreadID);
                                //alert(succe[j].CauseID);
                                if(gradeArr[x].value == succe[j].GreadID){
                                    gradeArr[x].checked = true;
                                    break;
                                }
                            }
                        }
                    },
                    function(err) {
                        showMassgeBox("提示",USER_DEL_FAIL,1,null);
                    }
                );
            },
            function(err){
                showMassgeBox("提示",USER_DEL_FAIL,1,null);
            }
        );
    }
    
    // 保存备课组长设置
    function Save() {
        var gradeArr = document.getElementsByName("cbGrade");
        var checkedArr = new Array();
        var uncheckedArr = new Array();
        
        for(var x = 0; x < gradeArr.length; x++ ) {
            if(gradeArr[x].checked) {
                checkedArr.push(Number(gradeArr[x].value));
            }
            else {
                uncheckedArr.push(Number(gradeArr[x].value));
            }
        }
        
        var groupID = self.parent.currCauseID;
        var teacherID = iEditTeachID;
        if(teacherID < 1)
            return;
        
        PageMethods.UpdateGSLeader(teacherID, groupID, checkedArr, uncheckedArr, 
            function(succ){
                CloseMask('popTable');
                Bind();
            },
            function(err){
                showMassgeBox("提示","备课组长设置失败",1,null);
            }
        );
    }
        
    function analyzeGrade(grade) {
        switch(grade) {
            case 1:
                return "一年级";
            case 2:
                return "二年级";
            case 3:
                return "三年级";
            case 4:
                return "四年级";
            case 5:
                return "五年级";
            case 6:
                return "六年级";
            case 7:
                return "初一";
            case 8:
                return "初二";
            case 9:
                return "初三";
            case 10:
                return "高一";
            case 11:
                return "高二";
            case 12:
                return "高三";
        }
    }
    

//    function delTeacherInfo(obj) {
//        PageMethods.DeleteTeacher(iCauseID,obj,function(succ){
//            if (succ > 0) {
//                Bind();
//            }

//        },function(err){
//            showMassgeBox("提示",USER_DEL_FAIL,1,null);
//        });
//    }
    
    function ShowMask() {
        showMask();
        self.parent.frames['left'].showMask();
    }
    
    function CloseMask(formId) {
        self.parent.frames['left'].activate = 1;
        editCauseID = 0;

        ClosePopForm(formId,true);
        hideMask();
        self.parent.frames['left'].hideMask();
    }
    
    function Load() {
        var arr = new Array();
        var u = window.location.toString();
        u = u.split('?');
        if (typeof(u[1]) == 'string') {
            u=u[1].split('&');
            for(var i=0;i<u.length;i++) {
                s=u[i].split("=");
                eval('arr["' + s[0] + '"]' + '="' + s[1]+'"');
            }
        }
        var id = arr['id'];
        iCauseID = id;
        
        if (id != null) { 
            Bind();
        }
    }
    
    function Bind() {
        document.getElementById('<%=btnBind.ClientID%>').click();
    }

    //设置行点击高亮
    function SetHightLight(obj) {
        iEditTeachID = obj.id;
        obj.style.backgroundColor = "#fffccf";
        var table = document.getElementById('teacherTable');
        for(var i =0 ; i < table.rows.length;i++)
        {
        var row = table.rows[i];
        if(row != null && row.id != obj.id)
            row.style.backgroundColor = "#ffffff";
        }
    }
    
    function IsExistTeacher() { 
        showMassgeBox("提示",TEACHER_IS_EXIST);
    }
    </script>
</body>
</html>
